home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / ANTENNA / YAGIU112 / NUM_ELEM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-07  |  1.6 KB  |  70 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <errno.h>
  4. #include "yagi.h"
  5.  
  6. extern int errno;
  7.  
  8. int get_number_of_elements(char *input_filename, int *driven , int *parasitic)
  9. {
  10.     FILE *ifp;
  11.     char *null, *line;
  12.     int num_elements;
  13.  
  14.     null=string(0L,12L);
  15.     line=string(0L,81L);
  16.     ifp=fopen(input_filename, "rt");
  17.     *driven=-1;
  18.     *parasitic=-1;
  19.     if(ifp == NULL)
  20.     {
  21.         fprintf(stderr,"Sorry, cant find file:  %s\n", input_filename);
  22.         exit(2);
  23.     }
  24.     /* Read line by line, looking for data on number of elements */
  25.     while(!feof(ifp))
  26.     {
  27.         fgets(line, 80, ifp);
  28.         if(strncmp(line,"ELEMENTS",8) == 0)  
  29.         {
  30.             sscanf(line,"%s %d\n", null, &num_elements);                        
  31.         }
  32.         if(strncmp(line,"DRIVEN",6) == 0)  
  33.         {
  34.             sscanf(line,"%s %d\n", null, driven);                        
  35.         }
  36.         if(strncmp(line,"PARASITIC",8) == 0)  
  37.         {
  38.             sscanf(line,"%s %d\n", null, parasitic);                        
  39.         }
  40.     }
  41. #ifdef DEBUG
  42.     errno=0;
  43. #endif
  44.     fclose(ifp);
  45.     if(num_elements == -1)
  46.         fprintf(stderr,"Error in data file %s: ELEMENTS undefined\n",input_filename); 
  47.     if(*driven == -1)
  48.         fprintf(stderr,"Error in data file %s : DRIVEN undefined\n", input_filename); 
  49.     if(*parasitic == -1)
  50.         fprintf(stderr,"Error in data file %s: PARASITIC undefined\n", input_filename); 
  51.     if(num_elements != *driven + *parasitic)
  52.     {
  53.         fprintf(stderr,"Check ELEMENTS, DRIVEN & PARASITIC in data file %s\n", input_filename);
  54.         fprintf(stderr,"ELEMENTS = %d DRIVEN = %d PARASITIC = %d\n", num_elements,      *driven, *parasitic);
  55.         exit(3);
  56.     }
  57.     free_string(line,0L,81L);
  58.     free_string(null,0L,12L);
  59.  
  60. #ifdef DEBUG
  61.     if(errno)
  62.     {
  63.         fprintf(stderr,"Errno =%d in mum_elem.c\n", errno);
  64.         exit(1);
  65.     }
  66. #endif
  67.     return(num_elements);
  68. }
  69.  
  70.